import java.util.Arrays;

public class Sort {
    public static void main(String[] args) {
        int[] a = {56,23,12,78,32,45,54,7};
        QuickSort(a);
        System.out.println(Arrays.toString(a));
    }

    private static void QuickSort(int[] a) {
        quick(a,0,a.length-1);
    }

    private static void quick(int[] a, int start, int end) {
        if(start >= end){
            return;
        }
        int piviot = piviotHare(a,start,end);
        quick(a,start,piviot-1);
        quick(a,piviot+1,end);
    }

    private static int piviotHare(int[] a, int left, int right) {
        int pivoit = left;
        while (left < right){
            if(left < right && a[right] >= a[pivoit]){
                right--;
            }
            if(left < right && a[left] <= a[pivoit]){
                left++;
            }
            swap(a,left,right);
        }
        swap(a,left,pivoit);
        return left;
    }

    private static void swap(int[] a, int left, int right) {
        int tmp = a[left];
        a[left] = a[right];
        a[right] = tmp;
    }
}
